﻿using BCCommon;
using BCDto.TMS.WorkingCompany;
using BCService.TMS.WorkingCompany;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.WorkingCompany
{

    /// <summary>
    /// 劳务公司接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class WorkingCompanyController : ManagementBaseController
    {
        #region var
        private IWorkingCompanyService workingCompanyService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public WorkingCompanyController(IWorkingCompanyService workingCompanyService)
        {
            this.workingCompanyService = workingCompanyService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新劳务公司纪录
        /// </summary>
        /// <param name="dto">劳务公司数据模型</param>
        /// <returns></returns>
        [Log("添加新劳务公司纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(WorkingCompanyRequestDto), 200)]
        public IActionResult Post([FromBody] WorkingCompanyRequestDto dto)
        {
            var a = workingCompanyService.Add(dto,Admin);
            return Ok(a);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改劳务公司纪录
        /// </summary>
        /// <param name="dto">劳务公司数据模型</param>
        /// <returns></returns>
        [Log("修改劳务公司纪录")]
        [HttpPut]
        [ProducesResponseType(typeof(WorkingCompanyDto), 200)]
        public IActionResult Put([FromBody] WorkingCompanyPutDto dto)
        {
            var a = Ok(workingCompanyService.Update(dto,Admin));
            return a;
        }
        #endregion


        #region PUT 启用禁用手动指派   
        /// <summary>
        /// 启用禁用手动指派
        /// </summary>
        /// <param name="workingCompanyId">劳务公司ID</param>
        /// <param name="enabledManualAssign">启用禁用手动指派</param>
        /// <returns></returns>
        [Log("启用禁用手动指派")]
        [HttpPut("[action]/{working_company_id}/{enable_manual_assign}")] 
        public IActionResult EnabledManualAssign(
            [FromRoute(Name ="working_company_id")] long workingCompanyId,
            [FromRoute(Name = "enable_manual_assign")] bool enabledManualAssign     )
        {
            workingCompanyService.EnabledManualAssign(workingCompanyId, enabledManualAssign,Admin);
            return NoContent();
        }
        #endregion



        #region 删除  
        /// <summary>
        /// 删除劳务公司纪录
        /// </summary>
        /// <param name="workingCompanyId">劳务公司ID</param>
        /// <returns></returns>
        [Log("删除劳务公司纪录")]
        [HttpDelete("{working_company_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "working_company_id")] long workingCompanyId)
        {
            workingCompanyService.Delete(workingCompanyId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条劳务公司纪录
        /// </summary>
        /// <param name="workingCompanyId">劳务公司ID</param>
        /// <returns></returns>
        [HttpGet("{working_company_id}")]
        [ProducesResponseType(typeof(WorkingCompanyDto), 200)]
        public IActionResult Get([FromRoute(Name = "working_company_id")] long workingCompanyId)
        {
            return (Ok(workingCompanyService.Get(workingCompanyId)));

        }
        #endregion

        #region Query 
        /// <summary>
        /// 查询劳务公司
        /// </summary>
        /// <param name="departmentId">部门Id</param>
		/// <param name="workingCompanyName">劳务公司名字</param>
		/// <param name="start">开始时间</param>
		/// <param name="end">结束时间</param>
		/// <param name="sortName">排序字段</param>
		/// <param name="ascending">升序</param>
		/// <param name="pageIndex">当前页码</param>
		/// <param name="pageSize">劳务公司每页数据条数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<WorkingCompanyDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "department_id")] long? departmentId,
            [FromQuery(Name = "working_company_name")] string workingCompanyName,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name ="end")]DateTime? end,
            [FromQuery(Name ="sort_name")]string sortName,
            [FromQuery(Name ="ascending")]bool? ascending,
            [FromQuery(Name = "index")] int? pageIndex = 1, 
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(workingCompanyService.Query(Admin,departmentId, workingCompanyName, start,end,sortName,ascending,pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion



        #region GetOnlyList 
        /// <summary>
        /// 获取劳务公司列表
        /// </summary> 
        /// <param name="departmentId">部门Id</param>
		/// <param name="workingCompanyName">劳务公司名字</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<WorkingCompanyDto>), 200)]
        public IActionResult GetOnlyList(
            [FromQuery(Name = "department_id")] long? departmentId,
            [FromQuery(Name = "working_company_name")] string workingCompanyName)
        {
            var a = Ok(workingCompanyService.GetOnlyList(Admin,departmentId, workingCompanyName));
            return a;
        }
        #endregion

    }

}
